<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/js/jquery-1.11.1/jquery-1.11.1.min.js"></script>
    <#include "/common/import.ftl"/>
</head>
<body>
<fieldset class="layui-elem-field layui-field-title ">
    <legend><li id="icon" class="layui-icon layui-icon-face-smile layui-anim layui-anim-rotate " style="font-size: 30px; color: #1E9FFF;" data-anim="layui-anim-rotate"></li> <span style="font-size: 8px">我在等风，也在等你</span></legend>
    <br>
    <div class="layui-field-box" style="width: 97%">
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <label class="layui-form-label">菜单ID  :</label>
                <div class="layui-input-block">
                    <input type="text" name="menuId" disabled="disabled"  autocomplete="off"  class="layui-input">
                    <div class="layui-form-mid layui-word-aux">辅助文字</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">菜单名称 * :</label>
                <div class="layui-input-block">
                    <input type="text" name="menuName" lay-verify="title" autocomplete="off" placeholder="请输入名称" class="layui-input">
                    <div class="layui-form-mid layui-word-aux">辅助文字</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">图标 ：</label>
                <div class="layui-input-block">
                    <input type="text" name="menuIcon"  placeholder="请输入class" autocomplete="off" class="layui-input">
                    <div class="layui-form-mid layui-word-aux">辅助文字</div>
                </div>

            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">排序 * ：</label>
                <div class="layui-input-block">
                    <input type="text" name="menuSort"  lay-verify="menuSort" placeholder="请输入排序" autocomplete="off" class="layui-input">
                    <div class="layui-form-mid layui-word-aux">辅助文字</div>
                </div>
            </div>
            <br><br>
            <div class="layui-form-item">
                <div class="layui-input-block" >
                    <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </form>
    </div>

</fieldset>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;
    layui.use(['form', 'layedit', 'laydate'], function(){
        //自定义验证规则  对应：lay-verify="menuSort"
        form.verify({
            title: function(value){
                if(value.length < 1){
                    $("#icon").removeClass("layui-icon-face-smile");
                    $("#icon").addClass("layui-icon-face-cry")
                    return '菜单名称至少得1个字符啊';
                }
            }
            ,menuSort: [ /[1-9]\d*/, '必需为数字']
            ,menuIcon: function(value){
                if(value.length < 1){
                    $("#icon").removeClass("layui-icon-face-smile");
                    $("#icon").addClass("layui-icon-face-cry")
                    return '图标至少得1个字符啊';
                }
            }
        });

        //注意：parent 是 JS 自带的全局对象，可用于操作父页面
        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        //监听提交
        form.on('submit(formDemo)', function(data){
            layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            })
            layer.load();
            $.ajax({
                url: '/menu/modifyMenu.ajax' ,
                type: 'post',
                async:false,
                data: {map: JSON.stringify(data.field)} ,
                dataType: 'json',
                async:false,
                success: function(json){
                    if(json["status"]=='Y'){
                        layer.msg('操作成功....', {icon: 6});
                        setTimeout(function(){
                            parent.layer.close(index);
                            parent.table.reload('dataTable');
                        }, 2000);
                    }else{
                        layer.msg('操作失败', {icon: 5});
                    }
                } ,
                error: function(){
                    alert("网络忙，请稍后重试！");
                },complete: function () {
                    layer.closeAll('loading');
                }
            });
            return false;
        });
    });
        function child(data) {
           //alert(data)
            //表单初始赋值
            form.val('example', {
                "username": "贤心" // "name": "value"
                , "password": "123456"
                , "interest": 1
                , "like[write]": true //复选框选中状态
                , "close": true //开关状态
                , "sex": "女"
                , "desc": "我爱 layui"
            });
        }
</script>

</body>
</html>